<?php

// +----------------------------------------------------------------------
// | 视图数据表
// +----------------------------------------------------------------------

namespace common\model;

use think\model\RelationModel;

class DocumentRelationModel extends RelationModel
{

    //自动验证
    protected $_validate = [
        ['relation_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['relation_type', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['post_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['relation_id', '1,80', '', self::EXISTS_VALIDATE, 'length'],
        ['relation_type', ['default', 'task_requirements', 'task_standard'], '', self::EXISTS_VALIDATE, 'in'],
    ];

    //自动完成
    protected $_auto = [
        ['created_by', 'fill_created_by', self::MODEL_INSERT, 'function'],
        ['created', 'time', self::MODEL_INSERT, 'function'],
        ['tenant_id', 'auto_fill_tenant_id', self::MODEL_INSERT, 'function'],
        ['param', 'json_encode', self::EXISTS_VALIDATE, 'function'],

    ];

    /**
     * 获取器：配置
     * @param $value
     * @return array|mixed
     */
    public function getParamAttr($value)
    {
        if (!empty($value)) {
            return json_decode($value, true);
        }
        return [];
    }
}
